import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import {
  GenerateTemplateForm,
  TemplateForm,
  TemplateQuery,
  TemplateUpdateForm,
  TemplateVO
} from '@/api/exam/template/types';

const apiPrefix = '/exam/template/';

/**
 * 查询题目分页列表
 * @param query
 * @returns {*}
 */
export const pageQuestion = (query?: TemplateQuery): AxiosPromise<TemplateVO[]> => {
  return request({
    url: apiPrefix + 'page',
    method: 'get',
    params: query
  });
};

/**
 * 查询题目列表
 * @param query
 * @returns {*}
 */
export const listQuestion = (query?: TemplateQuery): AxiosPromise<TemplateVO[]> => {
  return request({
    url: apiPrefix + 'list',
    method: 'get',
    params: query
  });
};

/**
 * 查询题目详细
 * @param questionId
 */
export const getQuestion = (questionId: string | number): AxiosPromise<TemplateVO> => {
  return request({
    url: apiPrefix + questionId,
    method: 'get'
  });
};
/**
 * 批量查询题目详细
 * @param questionIds
 */
export const getQuestionList = (questionIds): AxiosPromise<TemplateVO> => {
  return request({
    url: apiPrefix + 'batch/' + questionIds,
    method: 'get'
  });
};
/**
 * 新增题目
 * @param data
 */
export const addTemplate = (data: TemplateForm) => {
  return request({
    url: apiPrefix,
    method: 'post',
    data: data
  });
};

/**
 * 生成题目
 * @param data
 */
export const genQuestion = (data: GenerateTemplateForm) => {
  return request({
    url: apiPrefix + 'gen',
    method: 'post',
    data: data
  });
};

export const getGenStatus=(taskId:string)=>{
  return request({
    url: apiPrefix + 'gen/status/' + taskId,
    method: 'get',
  });
}

/**
 * 修改题目
 * @param data
 */
export const updateQuestion = (data: TemplateForm) => {
  return request({
    url: apiPrefix,
    method: 'put',
    data: data
  });
};

/*批量 新增|修改 题目*/
export const batchUpdateQuestion = (data: any) => {
  return request({
    url: apiPrefix + 'batchEdit',
    method: 'post',
    data: data
  });
};

/**
 * 删除题目
 * @param questionId
 */
export const delQuestion = (questionId: string | number | Array<string | number>) => {
  return request({
    url: apiPrefix + questionId,
    method: 'delete'
  });
};
/*下载题库导入模板*/
export const downloadTemplate = (name: string) => {
  return request({
    url: '/exam/repo/downloadTemplate',
    method: 'get',
    params: { name },
    responseType: 'blob'
  });
};
